package control;

import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Empresa;

/**
 *
 * @author Mario
 */
public final class ContextListener extends HttpServlet implements ServletContextListener {

   public void contextInitialized (ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext ();
        try {
           Empresa empresa=  Empresa.getEmpresa();
            servletContext.setAttribute ("empresa", empresa);
        }
        catch (Exception e) {
            servletContext.log ("No se pudo crear el atributo Empresa: " + e.getMessage ());
        }
    }

    public void contextDestroyed (ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext ();
        //Empresa empresa= = (LibrosBD) servletContext.getAttribute ("empresa");
        //empresa.close ();
        servletContext.removeAttribute ("BaseDatos");
    }



}
